# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.fcoin.kr_rest.constants import (symbol_list, currency_list, quote_currency_list)
from coin.exchange.fcoin.kr_rest.currency import FcoinCurrency


class FcoinProduct(NativeProduct):
  _exchange = "Fcoin"
  NativeCurrencyType = FcoinCurrency

  def __init__(self, base, quote):
    assert base.native_currency in currency_list, base
    assert quote.native_currency in quote_currency_list, quote
    assert base != quote, (base, quote)
    native_symbol = "%s%s" % (base.native_currency, quote.native_currency)
    super().__init__(base, quote, native_symbol)

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    assert isinstance(product, str), type(product)
    assert product in symbol_list, product
    for quote in quote_currency_list:
      if product.endswith(quote):
        base = product[:product.index(quote)]
        assert base in currency_list
        return FcoinProduct(FcoinCurrency.FromStrNativeCurrency(base),
                            FcoinCurrency.FromStrNativeCurrency(quote))
    raise ValueError(product)
